package com.job.structureType.agent.CGLIBProxy;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @Author 王博
 * @DateTime 2025-06-11 19:55
 */
public class ProxyFactory implements MethodInterceptor {
    StationTicketSeller stationTicketSeller = new StationTicketSeller();

    public StationTicketSeller getProxy() {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(stationTicketSeller.getClass());
        enhancer.setCallback(this);
        return (StationTicketSeller) enhancer.create();
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("代理卖票点卖票");
        Object invoke = method.invoke(stationTicketSeller, objects);
        return invoke;
    }
}
